﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Utility;

namespace Web.giamthi
{
    public partial class UCXepPhong : System.Web.UI.UserControl
    {
        XepPhongControl xpCtr = new XepPhongControl();
        LichControl lichCtr = new LichControl();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridView2.Visible = false;
                GridView1.AllowPaging = true;
                GridView1.PageSize = 10;
                LoadXepPhong();
            }
        }

        // Hiển thị danh sách xếp phòng
        private void LoadXepPhong()
        {
            GridView1.DataSource = xpCtr.GetListXepPhong();
            GridView1.DataBind();

        }
        
      
        // chọn 1 dòng để update xepphong
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = WebHelper.GetDataKey(GridView1, e).ToString();
            Response.Redirect("admin.aspx?page=xepphong&id=" + id + "");
        }

        // phân trang
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            WebHelper.pageIndexChanging(GridView1 , e);
            LoadXepPhong();
        }

        // chọn 1 dòng trong bảng lịch để update
        protected void GridView2_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            string id = WebHelper.GetIdGridView(GridView2 , 0 , e).ToString();
            Response.Redirect("admin.aspx?page=lich&id="+id+"");
        }

        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            GridView2.Visible = true;
            int pcid =Int32.Parse( WebHelper.GetIdGridView(GridView1, 1, e).ToString());
            GridView2.DataSource = lichCtr.GetLichByPCID(pcid);
            GridView2.DataBind();
        }


    }
}